package com.iot.user.controller;

import com.iot.commonutils.utils.Result;
import com.iot.user.dtos.UpdatePwdDto;
import com.iot.user.dtos.UserDto;
import com.iot.user.entity.User;
import com.iot.user.service.UpdatePwdService;
import com.iot.user.service.UserLoginService;
import com.iot.user.service.UserRegisteredService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 用户登录
 */
@RestController
@RequestMapping("/login")
@Api(value = "controller", tags = "用户登录相关接口")
public class LoginController {
    @Autowired
    private UserLoginService userLoginService;
    @Autowired
    private UserRegisteredService userRegisteredService;
    @Autowired
    private UpdatePwdService updatePwdService;


    @ApiOperation("用户登录")
    @PostMapping("/in")
    public Result login(@RequestBody UserDto dto) {
        return userLoginService.login(dto);
    }

    /**
     * 用户注册
     *
     * @param user
     */
    @ApiOperation("用户注册")
    @PostMapping("registered")
    public Result registeredUser(@RequestBody User user) {
        return userRegisteredService.registered(user);
    }

    /**
     * 修改密码
     *
     * @return
     */
    @ApiOperation("修改密码")
    @PostMapping("updatePwd")
    public Result updatePwd(@RequestBody UpdatePwdDto dto) {
        return updatePwdService.updatePwd(dto);
    }

}


